package client;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.nio.ByteBuffer;

public class Packet {

	private ByteBuffer info = ByteBuffer.allocate(1024);
	
	/**
	 * 构造一个类型为type的包
	 * @param type
	 */
	public Packet(short type) {
	}

	public void putInt(int start) {
		info.putInt(start);
	}

	public FromServer send(Socket s) {
		info.flip();
		try {
			s.getOutputStream().write(info.array());
			InputStream is = s.getInputStream();
			
			byte[] b = new byte[is.available()];
			is.read(b);
			return new FromServer(b);
			
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
}
